<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<?php

	/*
		Jax Calendar v1.34 - Copyright (c) 2002-2004, Andreas John aka Jack (tR)
		This program and it's moduls are Open Source in terms of General Public Licens (GPL) v2.0

		calendar.admin.php 		(admin system)
	*/
	
	
    // fit if nescessary:
	define( "PATH_TO_SCRIPT", "../" );

	// global variables (have to be fitted)
	require ( dirname(__FILE__) . "/".PATH_TO_SCRIPT."settings/calendar.settings.inc.php");

	// (If exists) include localization file for the favoured language
	if ( file_exists( dirname(__FILE__) . "/".PATH_TO_SCRIPT."languages/" . $language . ".inc.php" ) )
		define( "LOC_LANG", $language ); 
	else
		define( "LOC_LANG", $default_language ); 

	require_once ( dirname(__FILE__) ."/".PATH_TO_SCRIPT."languages/" . LOC_LANG . ".inc.php" );

	if (!empty( $_SERVER["PHP_SELF"] )) $PHP_SELF = $_SERVER["PHP_SELF"];
	
?>

<head>
	<title><?php echo $loc_lang["calendar"]." - ".$loc_lang["admin_program"]; ?></title>
	<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset ?>">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="expires" content="0">	

	<link rel="stylesheet" href="<?php echo PATH_TO_SCRIPT; ?>layout/css/jax/admin.css">
</head>

<body >
<div class="admin">
<div class="title"><?php echo $loc_lang["calendar"]." - ".$loc_lang["admin_program"]; ?></div>

<?php

	if ( $data_source == "mysql" )
	{
		// include class for database support
		require ( PATH_TO_SCRIPT."modules/classes/mysql.inc.php" );

		// prepare objects for database access
		// list of subscribers which signed in/off
		$calendar_list           = new mysql;
		$calendar_list->name     = $calendar_file;
		$calendar_list->server   = $db_server;
		$calendar_list->login    = $db_login;
		$calendar_list->password = $db_password;
		$calendar_list->database = $db_database;
		$calendar_list->init();
		$calendar_list->order_criterion = "ORDER BY 'event_start' DESC";

		$event_list           = new mysql;
		$event_list->name     = $event_file;
		$event_list->server   = $db_server;
		$event_list->login    = $db_login;
		$event_list->password = $db_password;
		$event_list->database = $db_database;
		$event_list->init();

	}

	if ( $data_source == "csvfile" )
	{
		// include class for CSV-textfile support
		require ( PATH_TO_SCRIPT."modules/classes/csvfile.inc.php" );

		// prepeare objects for file access
		// list of subscribers which signed in/off
		$calendar_list        = new csvfile;
		$calendar_list->name  = PATH_TO_SCRIPT.'cal_data/'.$calendar_file;
		$calendar_list->init();
		
		$event_list        = new csvfile;
		$event_list->name  = PATH_TO_SCRIPT.'cal_data/'.$event_file;
		$event_list->init();
	}
	

	if ( !empty( $_GET[ "do" ] ) ) { $do = $_GET[ "do" ]; } else { $do = "list"; }
	if ( !empty( $_GET[ "id" ] ) ) { $id = $_GET[ "id" ]; } else { $id = 0; }
	if ( !empty( $_GET[ "start" ] ) ) { $start = $_GET[ "start" ]; } else { $start = 0; }

	$ox_tail = "cal_id=$cal_id&language=$language&start=$start";


	$js_cal_format = split ('[/.-]', $_js_calendar_format);

	$keys = array_keys( $js_cal_format );
	foreach ($keys as $key)
	{
		$val = $js_cal_format[$key];
		$js_date_trans[$val] = $key;	
	}

	
function _translate_date_format( $date_str, $hour, $min )
{
	global $js_date_trans;	
	
	$date_split = list ( $part[0], $part[1], $part[2]) = split ('[/.-]', $date_str );
	
	$stamp = gmmktime( $hour, $min, 0,
			$part[ $js_date_trans["%m"] ],
			$part[ $js_date_trans["%d"] ],
			$part[ $js_date_trans["%Y"] ] );
			
	
	return $stamp;
}

if ( $do == "list" )
{
	$num_dates = $calendar_list->entries();
	
	$red_data = array();
	$calendar_list->get_entry(0,$red_data);
	
	echo <<<TABLEHEAD
<table class="index" width="100%" cellpadding="0" cellspacing="0">
<tr>
	<td class="icons">&nbsp;</td>
	<td class="icons">&nbsp;</td>
	<th>{$loc_lang["date"]}</th>
	<th>{$loc_lang["event"]}</th>
</tr>
TABLEHEAD;

	$start_ofs = $start * $admin_page_break;
	$last_page = floor($num_dates / $admin_page_break)+1;
	
	if ($start < $last_page-1 )
	{ 
		$start_next = $start+1;
		$link_next = "<a href=\"$PHP_SELF?$ox_tail&start=$start_next\">{$loc_lang["next_page"]}</a> &gt;";
	 }
	else 
	{ 
		$start_next = $start; 
		$link_next = ""; 
	}

	if ($start > 0 ) 
	{ 
		$start_prev = $start-1;
		$link_prev = "&lt; <a href=\"$PHP_SELF?$ox_tail&start=$start_prev\"> {$loc_lang["prev_page"]}</a>";
	} 
	else 
	{ 
		$start_prev = 0; 
		$link_prev = "";
	}

	$ii = 1;
	for ($i=1;$i<=$num_dates;$i++)
	{
		$new_id=$i-1;
		if ($i > $start_ofs)
		{
			echo '<tr valign="top" class="line_color'.($ii%2).'">'."\n"
			."	<td class=\"icons\">".'<a href="'.$PHP_SELF.'?do=edit_entry&id='.$new_id."&$ox_tail".'"><IMG SRC="'.PATH_TO_SCRIPT.'images/edit_entry.gif" border="0" alt="'.$loc_lang["change"].'">'."</a></td>\n"
			."	<td class=\"icons\">".'<a href="'.$PHP_SELF.'?do=delete_entry&id='.$new_id."&$ox_tail".'"><IMG SRC="'.PATH_TO_SCRIPT.'images/delete_entry.gif" border="0" alt="'.$loc_lang["delete"].'">'."</a></td>\n"
			."	<td class=\"date\">".'<nobr>'.gmdate("d.m.Y H:i",$red_data["event_start"])."</nobr></td>\n"
			."	<td>".$red_data["event_title"]."</td>\n</tr>\n";
			$ii++;
		}
		$calendar_list->get_next_entry( $red_data );
		if ($i >= $start_ofs + $admin_page_break ) break;
	}
	echo "</table>\n";
	$start++;
	echo '<div class="footline"><a href="'.$PHP_SELF."?do=new_entry&$ox_tail".'"><img src="'.PATH_TO_SCRIPT.'images/new_entry.gif" alt="'.$loc_lang["new_entry"].'" border="0">'."</a> &nbsp; {$loc_lang["new_entry"]}\n";
	echo "<div class=\"nav_page\" align=\"center\"><table><tr><td>$link_prev</td><td> | $start {$loc_lang["of_pages"]} $last_page | </td><td>$link_next</td></tr></table></div></div>";
}


if ( $do == "new_entry" )
{
	$entry1 = array();
	$entry2 = array();

	$mode = "create";
	$do = "edit_entry";
}

	function clean_quotes( $input )
	{
		$input = ereg_replace( '"', "&quot;", $input );
		return $input;
	}


if ( $do == "edit_entry" )
{
	if ( !empty( $mode ) && ($mode == "create" )) 
	{
		$nowww       = gmmktime();
		$nowww_year  = gmdate( "Y", $nowww );
		$nowww_month = gmdate( "m", $nowww );
		$nowww_day   = gmdate( "d", $nowww);

		$old_starts        = intval(gmmktime(0,0,0,$nowww_month,$nowww_day,$nowww_year));
		$old_ends          = $old_starts + 86399;
		$old_x24           = "1";
		$old_rem_start     = $old_starts;
		$old_rem_stop      = $old_starts + 86399;
		$old_status        = "";
		$old_event_title   = "";
		$old_event_key     = "";
		$old_event_description = "";
	}
	else 
	{
		$mode = "update";
		$entry1 = array();
		$calendar_list->get_entry( $id, $entry1 );
		
		$old_starts        = $entry1["event_start"];
		$old_ends          = $entry1["event_end"];
		$old_x24           = $entry1["x24"];
		$old_rem_start     = $entry1["reminder_start"];		
		$old_rem_stop      = $entry1["reminder_end"];		
		$old_status        = $entry1["status"];
		$old_event_title   = clean_quotes( $entry1["event_title"] );	
		
		$old_event_key     = $entry1["event_key"];

		$search_pattern = array(); $red_data = array();
		$search_pattern["event_key"] = $old_event_key;
		
		$pos = $event_list->find_entry( $search_pattern );
		$event_list->get_entry( $pos, $red_data );
		
		$old_event_description = ereg_replace("<br>", "\r\n", $red_data[ "event_description" ] );
		
//		$old_event_description = ( $red_data["event_description"] );
	}

	$old_start_date      = gmdate( $_local_date_format, $old_starts );	
	$old_start_hour      = gmdate( "H", $old_starts );
	$old_start_min       = gmdate( "i", $old_starts );

	$old_end_date        = gmdate( $_local_date_format, $old_ends );		
	$old_end_hour        = gmdate( "H", $old_ends );
	$old_end_min         = gmdate( "i", $old_ends );	

	$old_rem_start_date  = gmdate( $_local_date_format, $old_rem_start );	
	$old_rem_start_hour  = gmdate( "H", $old_rem_start );
	$old_rem_start_min   = gmdate( "i", $old_rem_start );

	$old_rem_stop_date   = gmdate( $_local_date_format, $old_rem_stop );	
	$old_rem_end_hour    = gmdate( "H", $old_rem_stop );
	$old_rem_end_min     = gmdate( "i", $old_rem_stop );
	
	if ($old_x24 == 1) $x24_chk = "checked"; else $x24_chk = "";

	$html_area_path = PATH_TO_SCRIPT."modules";
	echo <<< FORMSHEET
	<script language="Javascript1.2"><!-- // load htmlarea
		_editor_url = "$html_area_path/htmlarea/";                     // URL to htmlarea files
		var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
		if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
		if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
		if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
		if (win_ie_ver >= 5.5) {
			document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
			document.write(' language="Javascript1.2"></scr' + 'ipt>');  
		} else 
		{ document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
	// --></script>

	<!-- calendar stylesheet -->
	<link rel="stylesheet" type="text/css" media="all" href="../modules/jscalendar/calendar.css" title="win2k-cold-1" />
		
	<!-- main calendar program -->
	<script type="text/javascript" src="../modules/jscalendar/calendar.js"></script>
		
	<!-- language for the calendar -->
	<script type="text/javascript" src="../modules/jscalendar/lang/$_js_calendar_lang_file"></script>
		
	<!-- the following script defines the Calendar.setup helper function, which makes
	      adding a calendar a matter of 1 or 2 lines of code. -->
	<script type="text/javascript" src="../modules/jscalendar/calendar-setup.js"></script>
  
 
  
<form name="form_news" method="post" action="$PHP_SELF?do=$mode&id=$id&$ox_tail">
  <table cellspacing="0" class="input_box" align="center">
    <tr>
      <td>
        <table width="100%" border="0">
          <tr> 
            <td colspan="5">&nbsp;</td>
          </tr>
          <tr> 
            <td>&nbsp; 
              <input type="hidden" name="old_event_key" value="$old_event_key">
            </td>
            <td><b>{$loc_lang["event_span"]}</b></td>
            <td>$_local_date_format</td>
            <td>hh:mm</td>
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
            <td colspan="2"> 
{$loc_lang["start"]}:<br>
              <input type="text" name="new_start_date" id="f_new_start_date" value="$old_start_date" onchange="document.form_news.new_rem_start_date.value=document.form_news.new_start_date.value">
              <img src="../modules/jscalendar/img.gif" id="trigger_new_start_date" style="cursor: pointer; border: none;" title="{$loc_lang["date_select"]}"></td>
            <td> 
              <input type="text" name="new_start_hour" maxlength="2" size="3" value="$old_start_hour">
              : 
              <input type="text" name="new_start_min" maxlength="2" size="3" value="$old_start_min">
            </td>
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
            <td colspan="2">
{$loc_lang["end"]}:<br> 
              <input type="text" name="new_end_date" id="f_new_end_date" value="$old_end_date" onchange="document.form_news.new_rem_end_date.value=document.form_news.new_end_date.value">
              <img src="../modules/jscalendar/img.gif" id="trigger_new_end_date" style="cursor: pointer; border: none;" title="{$loc_lang["date_select"]}"></td>
            <td> 
              <input type="text" name="new_end_hour" maxlength="2" size="3" value="$old_end_hour">
              : 
              <input type="text" name="new_end_min" maxlength="2" size="3" value="$old_end_min">
            </td>
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
            <td colspan="4"> 
{$loc_lang["whole_day"]}: <br>
              <input type="checkbox" name="new_x24" value="1" $x24_chk>
            </td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td colspan="3">&nbsp;</td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
            <td colspan="4">
{$loc_lang["state"]}:<br> 
              <input type="text" name="new_status" maxlength="100" size="40" value="$old_status">&nbsp;<a href="../modules/pic_selector.php?image_list=categories" onclick="JavaScript: window.open( this.href,'PicSelector', 'width=400,height=280,left=100,top=50,resizable=yes');" target="PicSelector"><img src="../images/sel_img.gif" width="24" height="24" border="0"></a>
            </td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td colspan="3">&nbsp;</td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
            <td colspan="4"> 
{$loc_lang["title"]}:<br>
              <input type="text" name="new_event_title" size="40" value="$old_event_title">
            </td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
            <td colspan="4"> 
{$loc_lang["detailed_info"]}:<br>
              <textarea name="new_event_description" cols="40" rows="5">$old_event_description</textarea>
            </td>
          </tr>
          <tr> 
            <td colspan="5">&nbsp;</td>
          </tr>
          <tr> 
            <td colspan="5"> 
              <div align="center"> 
                <input type="submit" name="sendbutton" value="{$loc_lang["change"]}">
              </div>
            </td>
          </tr>
          <tr> 
            <td colspan="5">&nbsp;</td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
            <td colspan="2"><b>{$loc_lang["display_span"]}</b><br>$_local_date_format</td>
            <td>hh:mm</td>
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
            <td colspan="2">{$loc_lang["start"]}:<br> 
              <input type="text" name="new_rem_start_date" id="f_new_rem_start_date" value="$old_rem_start_date">
              <img src="../modules/jscalendar/img.gif" id="trigger_new_rem_start_date" style="cursor: pointer; border: none;" title="{$loc_lang["date_select"]}"></td>
            <td> 
              <input type="text" name="new_rem_start_hour" maxlength="2" size="3" value="$old_rem_start_hour">
              : 
              <input type="text" name="new_rem_start_min" maxlength="2" size="3" value="$old_rem_start_min">
            </td>
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
            <td colspan="2">
{$loc_lang["end"]}:<br> 
              <input type="text" name="new_rem_end_date" id="f_new_rem_end_date" value="$old_rem_stop_date">
              <img src="../modules/jscalendar/img.gif" id="trigger_new_rem_end_date" style="cursor: pointer; border: none;" title="{$loc_lang["date_select"]}"></td>
            <td> 
              <input type="text" name="new_rem_end_hour" maxlength="2" size="3" value="$old_rem_end_hour">
              : 
              <input type="text" name="new_rem_end_min" maxlength="2" size="3" value="$old_rem_end_min">
            </td>
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td colspan="5">&nbsp;</td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</form>

	<script type="text/javascript">
	Calendar.setup({
	        inputField     :    "f_new_start_date",         
	        ifFormat       :    "$_js_calendar_format",     
	        button         :    "trigger_new_start_date",   
	        singleClick    :    false                       
	    });
	
	Calendar.setup({
	        inputField     :    "f_new_end_date",         
	        ifFormat       :    "$_js_calendar_format",    
	        button         :    "trigger_new_end_date",   
	        singleClick    :    false                  
	    });
	
	Calendar.setup({
	        inputField     :    "f_new_rem_start_date",
	        ifFormat       :    "$_js_calendar_format",
	        button         :    "trigger_new_rem_start_date",
	        singleClick    :    false
	    });
	         
	Calendar.setup({
	        inputField     :    "f_new_rem_end_date",
	        ifFormat       :    "$_js_calendar_format",
	        button         :    "trigger_new_rem_end_date",
	        singleClick    :    false
	    });  
    
    </script>    

<script language="JavaScript1.2" defer>
	editor_generate('new_event_description');
</script>
FORMSHEET;
	
	exit;
}


if ( $do == "delete_entry" )
{
	echo "<p>{$loc_lang["delete_entry_confrm"]}</p>";
	echo "<p><a href=\"$PHP_SELF?do=remove_entry&id=$id&$ox_tail\">{$loc_lang["yes"]}</a></p>";
	echo "<p><a href=\"$PHP_SELF?$ox_tail\">{$loc_lang["no"]}</a></p><p>&nbsp;</p>";

	exit;
}

if ( $do == "remove_entry" )
{
	$entry1 = array();
	$calendar_list->get_entry( $id, $entry1 );
	$old_event_key = $entry1["event_key"];
	
	$calendar_list->delete( $id );

	$search_pattern = array();
	$search_pattern["event_key"] = $old_event_key;
		
	$pos = $event_list->find_entry( $search_pattern );
	$event_list->delete( $pos );

	echo '<meta http-equiv="refresh" content="0;URL='.$PHP_SELF."?do=list&$ox_tail".'">';
	exit;
}


if ( $do == "create" || $do == "update" )
{
	
	$old_event_key = $_POST[ "old_event_key" ];

	$new_event_start    = _translate_date_format( $_POST["new_start_date"], $_POST["new_start_hour"], $_POST["new_start_min"] );

	$new_event_end      = _translate_date_format( $_POST["new_end_date"], $_POST["new_end_hour"], $_POST["new_end_min"] );
	$new_reminder_start = _translate_date_format( $_POST["new_rem_start_date"], $_POST["new_rem_start_hour"], $_POST["new_rem_start_min"] );
	$new_reminder_end   = _translate_date_format( $_POST["new_rem_end_date"], $_POST["new_rem_end_hour"], $_POST["new_rem_end_min"] );
	
	if ( empty( $_POST[ "new_x24" ] ) ) $new_x24 = 0; else $new_x24 = $_POST[ "new_x24" ];

	$new_status         = $_POST[ "new_status" ];
	$new_event_title    =  clean_quotes( $_POST[ "new_event_title" ] );
	
	if ($data_source == "csvfile") $new_event_description = ereg_replace("(\r\n|\n|\r)", "<br>", $_POST[ "new_event_description" ] );
	else $new_event_description = $_POST[ "new_event_description" ];
	
	$new_event_key = md5( strval( $new_event_start . $new_event_end . $new_event_title ) );
}


if ( $do == "update" )
{
	$calendar_list->delete( $id );

	$search_pattern = array();
	$search_pattern["event_key"] = $old_event_key;
		
	$pos = $event_list->find_entry( $search_pattern );
	$event_list->delete( $pos );
		
	$do = "create";
}


if ( $do == "create" )
{
	$num_dates = $calendar_list->entries();
	
	$red_data = array();
	$calendar_list->get_entry(0,$red_data);

	$i = 0;
	while ( $i<$num_dates && $new_event_start <= $red_data["event_start"] )
	{
		$calendar_list->get_next_entry( $red_data );	
		$i++;
	}
	
	$to_cal = array();
	$to_cal["event_start"]    = $new_event_start;
	$to_cal["event_end"]      = $new_event_end;
	$to_cal["x24"]            = $new_x24;
	$to_cal["reminder_start"] = $new_reminder_start;
	$to_cal["reminder_end"]   = $new_reminder_end;
	$to_cal["status"]         = $new_status;
	$to_cal["event_title"]    = $new_event_title;
	$to_cal["event_key"]      = $new_event_key;		
	
	$calendar_list->insert( $i, $to_cal );
	
	$to_evt = array();
	$to_evt["event_key"]         = $new_event_key;
	$to_evt["event_description"] = $new_event_description;
	
	$event_list->append( $to_evt );
	
	echo '<meta http-equiv="refresh" content="0;URL='.$PHP_SELF."?do=list&$ox_tail".'">';
	exit;
	
}

?>
</div>
<!-- Please don't remove the link to the author's website!!! -->
<p class="author_info">Jax Calendar v1.34 by Jack (tR), <a href="http://www.jtr.de/scripting/php">www.jtr.de/scripting/php</a></p>
</body>
</html>